home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gas_251.zip / bin_251 / bfd / hpux-core.c < prev    next >
C/C++ Source or Header  |  1994-07-12  |  8KB  |  285 lines

  1. /* BFD back-end for HP/UX core files.
  2.    Copyright 1993, 1994 Free Software Foundation, Inc.
  3.    Written by Stu Grossman, Cygnus Support.
  4.    Converted to back-end form by Ian Lance Taylor, Cygnus SUpport
  5.  
  6. This file is part of BFD, the Binary File Descriptor library.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. /* This file can only be compiled on systems which use HP/UX style
  23.    core files.  In the config/XXXXXX.mh file for such a system add
  24.       HDEFINES=-DHPUX_CORE
  25.       HDEPFILES=hpux-core.o
  26.    */
  27.  
  28. #include "bfd.h"
  29. #include "sysdep.h"
  30. #include "libbfd.h"
  31.  
  32. #if defined (HOST_HPPAHPUX) || defined (HOST_HP300HPUX)
  33.  
  34. /* FIXME: sys/core.h doesn't exist for HPUX version 7.  HPUX version
  35.    5, 6, and 7 core files seem to be standard trad-core.c type core
  36.    files; can we just use trad-core.c in addition to this file?  */
  37.  
  38. #include <sys/core.h>
  39. #include <sys/utsname.h>
  40.  
  41. #endif /* HOST_HPPAHPUX */
  42.  
  43. #ifdef HOST_HPPABSD
  44.  
  45. /* Not a very swift place to put it, but that's where the BSD port
  46.    puts them.  */
  47. #include "/hpux/usr/include/sys/core.h"
  48.  
  49. #endif /* HOST_HPPABSD */
  50.  
  51. #include <stdio.h>
  52. #include <sys/types.h>
  53. #include <sys/param.h>
  54. #include <sys/dir.h>
  55. #include <signal.h>
  56. #include <machine/reg.h>
  57. #include <sys/user.h>        /* After a.out.h  */
  58. #include <sys/file.h>
  59. #include <errno.h>
  60.  
  61. /* These are stored in the bfd's tdata */
  62.  
  63. struct hpux_core_struct 
  64. {
  65.   int sig;
  66.   char cmd[MAXCOMLEN + 1];
  67.   asection *data_section;
  68.   asection *stack_section;
  69.   asection *reg_section;
  70. };
  71.  
  72. #define core_hdr(bfd) ((bfd)->tdata.hpux_core_data)
  73. #define core_signal(bfd) (core_hdr(bfd)->sig)
  74. #define core_command(bfd) (core_hdr(bfd)->cmd)
  75. #define core_datasec(bfd) (core_hdr(bfd)->data_section)
  76. #define core_stacksec(bfd) (core_hdr(bfd)->stack_section)
  77. #define core_regsec(bfd) (core_hdr(bfd)->reg_section)
  78.  
  79. static asection *
  80. make_bfd_asection (abfd, name, flags, _raw_size, vma, alignment_power)
  81.      bfd *abfd;
  82.      CONST char *name;
  83.      flagword flags;
  84.      bfd_size_type _raw_size;
  85.      bfd_vma vma;
  86.      unsigned int alignment_power;
  87. {
  88.   asection *asect;
  89.  
  90.   asect = bfd_make_section (abfd, name);
  91.   if (!asect)
  92.     return NULL;
  93.  
  94.   asect->flags = flags;
  95.   asect->_raw_size = _raw_size;
  96.   asect->vma = vma;
  97.   asect->filepos = bfd_tell (abfd);
  98.   asect->alignment_power = alignment_power;
  99.  
  100.   return asect;
  101. }
  102.  
  103. static asymbol *
  104. hpux_core_make_empty_symbol (abfd)
  105.      bfd *abfd;
  106. {
  107.   asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
  108.   if (new)
  109.     new->the_bfd = abfd;
  110.   return new;
  111. }
  112.  
  113. static const bfd_target *
  114. hpux_core_core_file_p (abfd)
  115.      bfd *abfd;
  116. {
  117.   core_hdr (abfd) = (struct hpux_core_struct *)
  118.     bfd_zalloc (abfd, sizeof (struct hpux_core_struct));
  119.   if (!core_hdr (abfd))
  120.     return NULL;
  121.  
  122.   while (1)
  123.     {
  124.       int val;
  125.       struct corehead core_header;
  126.  
  127.       val = bfd_read ((void *) &core_header, 1, sizeof core_header, abfd);
  128.       if (val <= 0)
  129.     break;
  130.       switch (core_header.type)
  131.     {
  132.     case CORE_KERNEL:
  133.     case CORE_FORMAT:
  134.       bfd_seek (abfd, core_header.len, SEEK_CUR);    /* Just skip this */
  135.       break;
  136.     case CORE_EXEC:
  137.       {
  138.         struct proc_exec proc_exec;
  139.         if (bfd_read ((void *) &proc_exec, 1, core_header.len, abfd)
  140.         != core_header.len)
  141.           break;
  142.         strncpy (core_command (abfd), proc_exec.cmd, MAXCOMLEN + 1);
  143.       }
  144.       break;
  145.     case CORE_PROC:
  146.       {
  147.         struct proc_info proc_info;
  148.         core_regsec (abfd) = make_bfd_asection (abfd, ".reg",
  149.                             SEC_HAS_CONTENTS,
  150.                             core_header.len,
  151.                 (int) &proc_info - (int) &proc_info.hw_regs,
  152.                             2);
  153.         if (bfd_read (&proc_info, 1, core_header.len, abfd)
  154.         != core_header.len)
  155.           break;
  156.         core_signal (abfd) = proc_info.sig;
  157.       }
  158.       if (!core_regsec (abfd))
  159.         return NULL;
  160.       break;
  161.     case CORE_DATA:
  162.       core_datasec (abfd) = make_bfd_asection (abfd, ".data",
  163.                     SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS,
  164.                            core_header.len,
  165.                            core_header.addr,
  166.                            2);
  167.       if (!core_datasec (abfd))
  168.         return NULL;
  169.       bfd_seek (abfd, core_header.len, SEEK_CUR);
  170.       break;
  171.     case CORE_STACK:
  172.       core_stacksec (abfd) = make_bfd_asection (abfd, ".stack",
  173.                     SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS,
  174.                             core_header.len,
  175.                             core_header.addr,
  176.                             2);
  177.       if (!core_stacksec (abfd))
  178.         return NULL;
  179.       bfd_seek (abfd, core_header.len, SEEK_CUR);
  180.       break;
  181.     default:
  182.       /* Falling into here is an error and should prevent this
  183.          target from matching.  That way systems which use hpux
  184.          cores along with other formats can still work.  */
  185.       return 0;
  186.     }
  187.     }
  188.  
  189.   /* OK, we believe you.  You're a core file (sure, sure).  */
  190.  
  191.   return abfd->xvec;
  192. }
  193.  
  194. static char *
  195. hpux_core_core_file_failing_command (abfd)
  196.      bfd *abfd;
  197. {
  198.   return core_command (abfd);
  199. }
  200.  
  201. /* ARGSUSED */
  202. static int
  203. hpux_core_core_file_failing_signal (abfd)
  204.      bfd *abfd;
  205. {
  206.   return core_signal (abfd);
  207. }
  208.  
  209. /* ARGSUSED */
  210. static boolean
  211. hpux_core_core_file_matches_executable_p (core_bfd, exec_bfd)
  212.      bfd *core_bfd, *exec_bfd;
  213. {
  214.   return true;            /* FIXME, We have no way of telling at this point */
  215. }
  216.  
  217. #define hpux_core_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound
  218. #define hpux_core_get_symtab _bfd_nosymbols_get_symtab
  219. #define hpux_core_print_symbol _bfd_nosymbols_print_symbol
  220. #define hpux_core_get_symbol_info _bfd_nosymbols_get_symbol_info
  221. #define hpux_core_bfd_is_local_label _bfd_nosymbols_bfd_is_local_label
  222. #define hpux_core_get_lineno _bfd_nosymbols_get_lineno
  223. #define hpux_core_find_nearest_line _bfd_nosymbols_find_nearest_line
  224. #define hpux_core_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
  225.  
  226. /* If somebody calls any byte-swapping routines, shoot them.  */
  227. void
  228. swap_abort()
  229. {
  230.   abort(); /* This way doesn't require any declaration for ANSI to fuck up */
  231. }
  232. #define    NO_GET    ((bfd_vma (*) PARAMS ((   const bfd_byte *))) swap_abort )
  233. #define    NO_PUT    ((void    (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
  234. #define    NO_SIGNED_GET \
  235.   ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
  236.  
  237. const bfd_target hpux_core_vec =
  238.   {
  239.     "hpux-core",
  240.     bfd_target_unknown_flavour,
  241.     true,            /* target byte order */
  242.     true,            /* target headers byte order */
  243.     (HAS_RELOC | EXEC_P |    /* object flags */
  244.      HAS_LINENO | HAS_DEBUG |
  245.      HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
  246.     (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  247.     0,                                               /* symbol prefix */
  248.     ' ',                           /* ar_pad_char */
  249.     16,                               /* ar_max_namelen */
  250.     3,                               /* minimum alignment power */
  251.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 64 bit data */
  252.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 32 bit data */
  253.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 16 bit data */
  254.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 64 bit hdrs */
  255.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 32 bit hdrs */
  256.     NO_GET, NO_SIGNED_GET, NO_PUT,    /* 16 bit hdrs */
  257.  
  258.     {                /* bfd_check_format */
  259.      _bfd_dummy_target,        /* unknown format */
  260.      _bfd_dummy_target,        /* object file */
  261.      _bfd_dummy_target,        /* archive */
  262.      hpux_core_core_file_p    /* a core file */
  263.     },
  264.     {                /* bfd_set_format */
  265.      bfd_false, bfd_false,
  266.      bfd_false, bfd_false
  267.     },
  268.     {                /* bfd_write_contents */
  269.      bfd_false, bfd_false,
  270.      bfd_false, bfd_false
  271.     },
  272.     
  273.        BFD_JUMP_TABLE_GENERIC (_bfd_generic),
  274.        BFD_JUMP_TABLE_COPY (_bfd_generic),
  275.        BFD_JUMP_TABLE_CORE (hpux_core),
  276.        BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
  277.        BFD_JUMP_TABLE_SYMBOLS (hpux_core),
  278.        BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
  279.        BFD_JUMP_TABLE_WRITE (_bfd_generic),
  280.        BFD_JUMP_TABLE_LINK (_bfd_nolink),
  281.        BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
  282.  
  283.     (PTR) 0            /* backend_data */
  284. };
  285.